/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import java.math.*;
import java.util.*;

/**
 *
 * @author pc0129
 */
public class FactorFinder {

    ArrayList<String> factors;
    String returnthis = "null";
    String[] args = null;

    public static void main(String[] args) {
    }

    public void factorProcess(String serverCommand) {
        args = serverCommand.split(" ");
        run();
    }

    public void run() {
        factors = new ArrayList<String>();
        BigInteger target = new BigInteger(args[0]);
        BigInteger lowerBound = new BigInteger(args[1]);
        BigInteger upperBound = new BigInteger(args[2]);
        //System.out.println(lowerBound.toString() + " " + upperBound.toString());
        factorSearch(lowerBound, target, upperBound);
        for (String s : factors) {
            System.out.print(s + "*");
        }
    }

    public void factorSearch(BigInteger lowerBound, BigInteger target, BigInteger upperBound) {
        
        System.out.println("-----------------------");

        System.out.println("I am client:");
        System.out.println(Client.address);
        System.out.println("lowerBound");
        System.out.println(lowerBound.toString());
        System.out.println("upperBound");
        System.out.println(upperBound.toString());
        System.out.println("target");
        System.out.println(target.toString());
        System.out.println("-----------------------");
        while (lowerBound.compareTo(upperBound.add(new BigInteger("1"))) == -1) {
//System.out.println("this is the current test :"+ lowerBound.toString());
            if (target.mod(lowerBound).compareTo(new BigInteger("0")) == 0) {
                factors.add(lowerBound.toString());
                target = target.divide(lowerBound);
                System.out.println(lowerBound.toString());
            } else {
                lowerBound = lowerBound.nextProbablePrime();
            }
        }



    }

    public String getArrayList() {
        //System.out.println("in getArrayList()");
        //System.out.println("factors" + factors);
        returnthis = new String();
        if (factors.size() >= 1) {
            //System.out.println("This test was run");
            
            for (String s : factors) {
                returnthis = returnthis + s + " ";
                System.out.println("Factors:" + s);

            }
            factors = new ArrayList<String>();
            //System.out.println("AfterCreation:" + factors);

        }else {
            return "null";
        }
        //System.out.println("Something is happening");
        //System.out.println(returnthis);
        return returnthis;

    }
}



